package com.umeng.lx;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.umeng.lx.Adapter.MyVpAdapter;
import com.umeng.lx.Fragment.AFragment;
import com.umeng.lx.Fragment.BFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.Vp)
    ViewPager Vp;
    @BindView(R.id.tablayout)
    TabLayout tablayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        initView();

    }

    private void initView() {
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(new AFragment());
        fragments.add(new BFragment());

        MyVpAdapter myVpAdapter = new MyVpAdapter(getSupportFragmentManager(), fragments);
        myVpAdapter.notifyDataSetChanged();

        Vp.setAdapter(myVpAdapter);
        tablayout.setupWithViewPager(Vp);

        tablayout.getTabAt(0).setText("首页").setIcon(R.drawable.ths);
        tablayout.getTabAt(1).setText("消息").setIcon(R.drawable.ths);
    }
}
